package com.silent.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.silent.domain.Girl;
import com.silent.enums.RestfulEnum;
import com.silent.exception.GirlException;
import com.silent.repository.GirlRepository;

/**
 * @author Silent-Y
 *
 */
@Service
public class GirlService {
	
	@Autowired
	private GirlRepository girlRepository;

	@Transactional
	public void insertTwo(){
		
		Girl girlA = new Girl();
		girlA.setAge(21);
		girlA.setCupSize("A");
		
		girlRepository.save(girlA);
		
		Girl girlB = new Girl();
		girlB.setAge(22);
		girlB.setCupSize("B");
		
		girlRepository.save(girlB);
	}
	
	public void getAge(Integer id) throws Exception{
		
		Girl girl = girlRepository.findOne(id);
		Integer age = girl.getAge();
		
		if(age < 10){
			//返回“小学生”
			throw new GirlException(RestfulEnum.PRIMARY);
		}else if(age > 10 && age < 16){
			//返回“中学生”
			throw new GirlException(RestfulEnum.MIDDLE);
		}
	}
}
